package com.base.caselib.adapter;

import android.content.Context;
import android.view.View;
import android.widget.CheckBox;

import com.base.caselib.R;
import com.base.caselib.bean.LawStatuteDetailListBean;
import com.base.commonlib.recy.BasicRecyViewHolder;
import com.base.commonlib.recy.HFSingleTypeRecyAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/10/21.
 */

public class LawStatuteItemsListAdapter extends HFSingleTypeRecyAdapter<LawStatuteDetailListBean,LawStatuteItemsListAdapter.ViewHolder> {

    Context mContext;


    public LawStatuteItemsListAdapter(int resId, Context mContext) {
        super(resId);
        this.mContext=mContext;

    }

    @Override
    public ViewHolder buildViewHolder(View itemView) {
        return new ViewHolder(itemView);
    }


    private List<LawStatuteDetailListBean> lawStatuteDetailListBeans=new ArrayList<>();


    public List<LawStatuteDetailListBean> getSelectDataList(){
       return lawStatuteDetailListBeans;
    }

    @Override
    public void bindDataToHolder(final ViewHolder holder, final LawStatuteDetailListBean bean, final int position) {
        holder.tv_dictvalue.setText(bean.getItemAct());
        holder.tv_dictvalue.setChecked(bean.isChecked());
//        if (position==0){
//            holder.tv_dictvalue.setChecked(true);
//            bean.setChecked(true);
//            lawStatuteDetailListBeans.add(bean);
//        }

        holder.tv_dictvalue.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (holder.tv_dictvalue.isChecked()){
                    bean.setChecked(true);
                    lawStatuteDetailListBeans.add(bean);
                }else {
                    bean.setChecked(false);
                    lawStatuteDetailListBeans.remove(bean);
                }
            }
        });


    }

    public static class ViewHolder extends BasicRecyViewHolder {

        CheckBox tv_dictvalue;

        public ViewHolder(View itemView) {
            super(itemView);
            tv_dictvalue=(CheckBox) itemView.findViewById(R.id.tv_dictvalue);
        }


    }
}
